import pandas as pd
import matplotlib.pyplot as plt

import matplotlib

matplotlib.use("TkAgg")


cjoints = pd.read_csv("data/qualtrics/brazil/brazil_conjoint_estimates.csv")

# attitudes

questions = [
    "Me and my friends \n well represented",
    "People like me \n treated unfairly in this economy",
    "Differences are larger \n with the elite",
    "There is no \n real democracy",
    "Migrants threaten \n local workers",
]

outcomes = [
    "amigos",
    "pessoas",
    "diferencas",
    "democracia",
    "migrantes",
]

levels = [
    "Informal worker \n (b = Formal contributions)",
    "Strict schedules with no breaks \n (b=Flexible schedules)",
    "Promotions based on productivity and \n diversity quotas \n (b=Promotions based on productivity)",
    "No benefits beyond national agreement \n (b=Health package and childcare)",
    "Fixed-term contracts \n (b=Permanent contracts)",
    "CEO earns 1000 times average employee \n (b=CEO earns 10 times average employee)",
    "A large MNC \n (b = A medium-sized family firm)",
]

n = 0

fig, axs = plt.subplots(1, len(outcomes), figsize=(14, 8))
for ax, outcome, question in zip(axs, outcomes, questions):
    n = n + 1
    ax.set_xlim(-0.2, 0.2)
    ax.errorbar(
        cjoints[outcome],
        range(0, cjoints.shape[0]),
        xerr=cjoints["ci_length_" + outcome],
        fmt="o",
        markersize=3,
    )
    if n == 1:
        ax.set_yticks(range(0, cjoints.shape[0]))
        ax.set_yticklabels(levels, fontsize=10)
    else:
        ax.label_outer()
    ax.set_title(question, fontsize=10)
    ax.axvline(0, color="red", lw=1, alpha=0.75, ls="dashed")

plt.savefig(
    "plots/qualtrics_br/cjoint_attitudes.eps", format="eps", bbox_inches="tight"
)
# behaviors

questions = [
    "Take part \n in protests",
    "Be part of group \n to overthrow government",
    "Protest against \n immigration",
    "Vote for parties \n that reject political system",
]

outcomes = ["manifestacoes", "derrubar", "protestos_migr", "partidos_opoem"]

levels = [
    "Informal worker \n (b = Formal contributions)",
    "Strict schedules with no breaks \n (b=Flexible schedules)",
    "Promotions based on productivity and \n diversity quotas \n (b=Promotions based on productivity)",
    "No benefits beyond national agreement \n (b=Health package and childcare)",
    "Fixed-term contracts \n (b=Permanent contracts)",
    "CEO earns 1000 times average employee \n (b=CEO earns 10 times average employee)",
    "A large MNC \n (b = A medium-sized family firm)",
]


n = 0

fig, axs = plt.subplots(1, len(outcomes), figsize=(14, 8))
for ax, outcome, question in zip(axs, outcomes, questions):
    n = n + 1
    ax.set_xlim(-0.2, 0.2)
    ax.errorbar(
        cjoints[outcome],
        range(0, cjoints.shape[0]),
        xerr=cjoints["ci_length_" + outcome],
        fmt="o",
        markersize=3,
    )
    if n == 1:
        ax.set_yticks(range(0, cjoints.shape[0]))
        ax.set_yticklabels(levels, fontsize=10)
    else:
        ax.label_outer()
    ax.set_title(question, fontsize=10)
    ax.axvline(0, color="red", lw=1, alpha=0.75, ls="dashed")

plt.savefig(
    "plots/qualtrics_br/cjoint_behaviors.eps", format="eps", bbox_inches="tight"
)
